package com.shell.arouter.update

import com.durian.base.rxhttp.RxHttp
import com.durian.base.rxhttp.await.tryAwait
import com.durian.base.rxhttp.param.asClass
import com.durian.base.update.entity.VersionEntity
import com.durian.base.update.proxy.impl.DefaultHttpRequest

class ReaderUpdateHttpRequest : DefaultHttpRequest(){

    override suspend fun sendRequest(): VersionEntity? {
        return RxHttp.get("http://rest.apizza.net/mock/1df8c1addf0463feda32eb83f7e90edb/hah")
            .asClass<AppUpdateData>().tryAwait()?.let {
                val versionEntity = VersionEntity()
                versionEntity.versionName = it.versionShort?:""
                versionEntity.versionCode = it.build?.toInt() ?: 0
                versionEntity.downloadUrl = it.installUrl ?: ""
                versionEntity.forceUpdate = it.force
                versionEntity.updateLog = it.changelog?:""
                versionEntity.md5 = it.md5?:""
                return versionEntity
            }
    }

}